<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      th:replace="pages/common/main :: layout(~{::title}, ~{::section}, ~{}, ~{::script})">
    <head>
        <title>数据源</title>
    </head>
    <body>
        <section>

            <div class="layui-card">
                <div class="layui-card-header">[[${header}]]</div>
                <div class="layui-card-body">
                    <form name="menu" class="layui-form layui-form-pane" lay-filter="FORM">

                        <div class="layui-form-item">
                            <label class="layui-form-label" for="datasource-name">名称</label>
                            <div class="layui-input-block">
                                <input id="datasource-name" name="name" class="layui-input" lay-verify="required"
                                       th:value="${datasource.getName()}" th:readonly="${isUpdate}"/>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label" for="datasource-description">描述</label>
                            <div class="layui-input-block">
                                <input id="datasource-description" name="description" class="layui-input" lay-verify="required"
                                       th:value="${datasource.getDescription()}"/>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label" for="datasource-username">用户名</label>
                            <div class="layui-input-block">
                                <input id="datasource-username" name="username" class="layui-input" lay-verify="required"
                                       th:value="${datasource.getUsername()}"/>
                            </div>
                        </div>
                        
                        <div class="layui-form-item">
                            <label class="layui-form-label" for="datasource-password">密码</label>
                            <div class="layui-input-block">
                                <input id="datasource-password" name="password" class="layui-input" lay-verify="required"
                                       th:value="${datasource.getPassword()}"/>
                            </div>
                        </div>
                        
                        <div class="layui-form-item">
                            <label class="layui-form-label" for="datasource-driver">驱动</label>
                            <div class="layui-input-block">
                                <input id="datasource-driver" name="driver" class="layui-input" lay-verify="required"
                                       th:value="${datasource.getDriver()}"/>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label" for="datasource-url">URL</label>
                            <div class="layui-input-block">
                                <textarea id="datasource-url" name="url" class="layui-textarea">[[${datasource.getUrl()}]]</textarea>
                            </div>
                        </div>

                        <div class="layui-form-item layui-input-block">
                            <button type="submit" class="layui-btn" lay-submit lay-filter="form-submit">立即提交</button>
                        </div>

                    </form>
                </div>
            </div>

        </section>
        <script th:inline="javascript">
            layui.use(['element', 'form', 'jquery', 'ax', 'admin'], function () {
                var form = layui.form,
                    $ax = layui.ax;

                form.on('submit(form-submit)', function (data) {
                    var ajax = new $ax(Kong.ctxPath + "/sys/datasource/save", function (data) {
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index)
                        top.layui.admin.refresh()
                    });
                    // console.log(data)
                    // ajax.setHeadersValue("Model-Class", "");
                    ajax.setMethod("post");
                    ajax.setData(data.field);
                    ajax.send();
                    return false;
                })

            });

        </script>
    </body>
</html>